import shutil
from git import Repo
import os

class GitClient:
    @staticmethod
    def clone(repouUrl, localHome, localHub='.'):
        localDir=os.path.join(localHub, localHome)
        repo = None
        if( os.path.exists(localDir)):
            try:
                repo = Repo(localDir)
            except Exception as e:
                print(e)
        else:
            os.makedirs(localHub, exist_ok=True)
            repo = Repo.clone_from(repouUrl, localDir)
        return repo
    @staticmethod
    def cloneForce(repouUrl, localHome, localHub='.'):
        localDir=os.path.join(localHub, localHome)
        repo = None
        if( os.path.exists(localDir)):
            try:
                shutil.rmtree(localDir)
            except Exception as e:
                print(e)
        os.makedirs(localHub, exist_ok=True)
        repo = Repo.clone_from(repouUrl, localDir)
        return repo

if __name__ == '__main__':

    GitClient.clone('git@gitee.com:bbxxone/autoble.git', 'test', '/Users/zhaojinhui/Desktop/Auto/autonsole')

